<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作者" prop="zuoZhe">
        <el-input
          v-model="queryParams.zuoZhe"
          placeholder="请输入作者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键词" prop="guanJianCi">
        <el-input
          v-model="queryParams.guanJianCi"
          placeholder="请输入关键词"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="TdmWenXianShuJuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="leiXing" />
      <el-table-column label="类型" prop="baoJianLeiXing" >
        <template slot-scope="scope">
          <span v-if="scope.row.leiXing == 1">单体化合物</span>
          <span v-if="scope.row.leiXing == 2">复杂样品</span>
          <span v-if="scope.row.leiXing == 3">致敏文献</span>
          <span v-if="scope.row.leiXing == 4">文献库</span>
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center" prop="biaoTi" />
      <el-table-column label="作者" align="center" prop="zuoZhe" />
      <el-table-column label="关键词" align="center" prop="guanJianCi" />
      <el-table-column label="年份" align="center" prop="nianFen" />
<!--      <el-table-column label="审核状态" align="center" prop="shenHe" />-->
      <el-table-column label="处理状态" align="center" key="shenHe" id="colourType">
        <template slot-scope="scope">
          <el-button type="success">
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 0 ">未审核</span>
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 1 ">已初审</span>
            <span @click="getValue(scope.row)" v-if="scope.row.shenHe == 2 ">已终审</span>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tdmdata:TdmWenXianShuJuComplex:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改文献数据库管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<!--        <el-form-item label="1:单体化合物 2:复杂样品 3:致敏文献 4:文献库" prop="leiXing">-->
<!--          <el-input v-model="form.leiXing" placeholder="请输入1:单体化合物 2:复杂样品 3:致敏文献 4:文献库" />-->
<!--        </el-form-item>-->
        <el-form-item label="药物类型" prop="typeId">
          <el-checkbox-group v-model="form.typeId" @change="handleSelectionChange">
            <el-checkbox v-for="date in typeIdArr" :label="date.key" :key="date.key">{{date.label}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="标题" prop="biaoTi">
          <el-input v-model="form.biaoTi" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="作者" prop="zuoZhe">
          <el-input v-model="form.zuoZhe" placeholder="请输入作者" />
        </el-form-item>
        <el-form-item label="关键词" prop="guanJianCi">
          <el-input v-model="form.guanJianCi" placeholder="请输入关键词" />
        </el-form-item>
        <el-form-item label="年份" prop="nianFen">
          <el-input v-model="form.nianFen" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="来源" prop="laiYuan">
          <el-input v-model="form.laiYuan" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="摘要" prop="zhaiYao">
          <el-input v-model="form.zhaiYao" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="参考链接" prop="canKaoLianJie">
          <el-input v-model="form.canKaoLianJie" placeholder="请输入参考链接" />
        </el-form-item>
<!--        <el-form-item label="参考附件">-->
<!--          <file-upload v-model="form.canKaoFuJian"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="药品名称" prop="yaoPinMingCheng">-->
<!--          <el-input v-model="form.yaoPinMingCheng" placeholder="请输入药品名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="数据参数" prop="shuJuCanShu">-->
<!--          <el-input v-model="form.shuJuCanShu" placeholder="请输入数据参数" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTdmWenXianShuJu, getTdmWenXianShuJu, delTdmWenXianShuJu, addTdmWenXianShuJu, updateTdmWenXianShuJu ,to_examine} from "@/api/tdmdata/TdmWenXianShuJuComplex";

export default {
  name: "TdmWenXianShuJu",
  data() {
    return {
      typeIdArr: [
        {key: "10", label: "通用",},
        {key: "1001", label: "复杂体系",},
        {key: "1002", label: "肿瘤药物",},
        {key: "100101", label: "过敏物",}],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文献数据库管理表格数据
      TdmWenXianShuJuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        typeId: [],
        leiXing: null,
        biaoTi: null,
        zuoZhe: null,
        guanJianCi: null,
        nianFen: null,
        laiYuan: null,
        zhaiYao: null,
        canKaoLianJie: null,
        canKaoFuJian: null,
        createById: null,
        createByName: null,
        updateById: null,
        updateByName: null,
        shenHe: null,
        yaoPinMingCheng: null,
        shuJuCanShu: null,
        yaowujiben: null,
        yaodaidong: null,
        zhiliaoyaowu: null,
        yaopwuxianghu: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        biaoTi: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        zuoZhe: [
          { required: true, message: "作者不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询文献数据库管理列表 */
    getList() {
      this.loading = true;
      listTdmWenXianShuJu(this.queryParams).then(response => {
        this.TdmWenXianShuJuList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        typeId: ['10'],
        leiXing: null,
        biaoTi: null,
        zuoZhe: null,
        guanJianCi: null,
        nianFen: null,
        laiYuan: null,
        zhaiYao: null,
        canKaoLianJie: null,
        canKaoFuJian: null,
        createById: null,
        createByName: null,
        createTime: null,
        updateById: null,
        updateByName: null,
        updateTime: null,
        shenHe: null,
        yaoPinMingCheng: null,
        shuJuCanShu: null,
        yaowujiben: null,
        yaodaidong: null,
        zhiliaoyaowu: null,
        yaopwuxianghu: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    getValue: function(row) {
      // 修改值为已初审
      if (row.shenHe == 0){
        to_examine(row.id,1,'tdm_wen_xian_shu_ju');
        // 修改值为已终审
      } else if (row.shenHe == 1){
        to_examine(row.id,2,'tdm_wen_xian_shu_ju');
      } else if (row.shenHe == 2){
        this.$modal.msgSuccess("已终审！");
      }
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文献数据库管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTdmWenXianShuJu(id).then(response => {
        this.form = response.data;
        this.form.typeId = this.form.typeId.split(",");
        this.open = true;
        this.title = "修改文献数据库管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.typeId = this.form.typeId.join(",");
          if (this.form.id != null) {
            updateTdmWenXianShuJu(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTdmWenXianShuJu(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除文献数据库管理编号为"' + ids + '"的数据项？').then(function() {
        return delTdmWenXianShuJu(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('tdmdata/TdmWenXianShuJu/export', {
        ...this.queryParams
      }, `TdmWenXianShuJu_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
